#ifndef ANIMATION_H
#define ANIMATION_H

#include "abstractobject.h"
//class Texture;
// TODO: see why we must #include texture.h here and why forwarding texture declaration doesn't work
#include "texture.h"

class QUndoStack;

class CollisionShape;

struct AnimationFrame
{
    QRect rect;
    QList<QPointer<CollisionShape> > collisionShapes;
    // collision shapes undo stack
    QPointer<QUndoStack> csUndoStack;
};

class Animation : public AbstractObject
{
    Q_OBJECT
public:
    explicit Animation(QObject* parent = 0);

    AnimationFrame currentFrame() const;
    const AnimationFrame& frame(int nIndex) const;
    AnimationFrame& frame(int nIndex);

    const QList<AnimationFrame>& frames() const;

    void setFrame(int nIndex, const AnimationFrame& frame);

    void generateAnimation(int xPattern, int yPattern, int nNumFrames);

    int xPattern() const;
    int yPattern() const;
    int numFrames() const;

    QPointer<Texture> texture() const;
private:
    QPointer<Texture> m_texture;
    QList<AnimationFrame> m_frames;
    int m_nCurrentFrame;
    bool m_bLoop;

    int m_nXPattern;
    int m_nYPattern;
    int m_nNumFrames;

    bool m_bSameCollisionShapeForAllFrames;
    // is there is same collision shape for all frames
    QList<QPointer<CollisionShape> > m_collisionShapes;
public slots:
    void setCurrentFrame(int nFrame);
    void setTexture(QPointer<Texture> texture);
signals:
    void currentFrameChanged(int nFrame);
    void textureChanged(QPointer<Texture> texture);
};

#endif // ANIMATION_H
